package com.tianlh.service.exam;

import java.util.concurrent.locks.LockSupport;

/**
 * @author 黑子
 * @Date 2018/2/5 16:33
 */
public class LockSupportTest {

    public static void main(String[] args) {
        final long threshold = 5000;
        final Thread main = Thread.currentThread();
        new Thread(() -> {
            long startTime = System.currentTimeMillis();
            while (System.currentTimeMillis() - startTime <= threshold){}
            System.out.println(LockSupport.getBlocker(main));
            // 中断时也会退出阻塞
            //main.interrupt();
            LockSupport.unpark(main);
            System.out.println("超时unpark");
        }).start();
        System.out.println("start..........");
        LockSupport.park();
        System.out.println("unpark.........");
    }
}
